home *** CD-ROM | disk | FTP | other *** search
/ Erotic Games: Memory / Erotic Games: Memory.iso / mac / air_installers / AdobeAIR.exe / setup.swf / scripts / mx / skins / RectangularBorder.as < prev   
Text File  |  2009-02-12  |  9KB  |  264 lines

  1. package mx.skins
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.display.Graphics;
  5.    import flash.display.Loader;
  6.    import flash.display.LoaderInfo;
  7.    import flash.display.Shape;
  8.    import flash.events.ErrorEvent;
  9.    import flash.events.Event;
  10.    import flash.events.IOErrorEvent;
  11.    import flash.geom.Rectangle;
  12.    import flash.net.URLRequest;
  13.    import flash.system.ApplicationDomain;
  14.    import flash.system.LoaderContext;
  15.    import flash.utils.getDefinitionByName;
  16.    import mx.core.EdgeMetrics;
  17.    import mx.core.FlexLoader;
  18.    import mx.core.FlexShape;
  19.    import mx.core.IChildList;
  20.    import mx.core.IContainer;
  21.    import mx.core.IRawChildrenContainer;
  22.    import mx.core.IRectangularBorder;
  23.    import mx.core.mx_internal;
  24.    import mx.resources.IResourceManager;
  25.    import mx.resources.ResourceManager;
  26.    import mx.styles.ISimpleStyleClient;
  27.    
  28.    use namespace mx_internal;
  29.    
  30.    public class RectangularBorder extends Border implements IRectangularBorder
  31.    {
  32.       
  33.       mx_internal static const VERSION:String = "3.0.0.0";
  34.        
  35.       
  36.       private var backgroundImage:DisplayObject;
  37.       
  38.       private var backgroundImageHeight:Number;
  39.       
  40.       private var _backgroundImageBounds:Rectangle;
  41.       
  42.       private var backgroundImageStyle:Object;
  43.       
  44.       private var backgroundImageWidth:Number;
  45.       
  46.       private var resourceManager:IResourceManager;
  47.       
  48.       public function RectangularBorder()
  49.       {
  50.          resourceManager = ResourceManager.getInstance();
  51.          super();
  52.          addEventListener(Event.REMOVED,removedHandler);
  53.       }
  54.       
  55.       public function layoutBackgroundImage() : void
  56.       {
  57.          var _loc4_:Number = NaN;
  58.          var _loc5_:Number = NaN;
  59.          var _loc7_:Number = NaN;
  60.          var _loc8_:Number = NaN;
  61.          var _loc14_:Number = NaN;
  62.          var _loc15_:Graphics = null;
  63.          var _loc1_:DisplayObject = parent;
  64.          var _loc2_:EdgeMetrics = _loc1_ is IContainer ? IContainer(_loc1_).viewMetrics : borderMetrics;
  65.          var _loc3_:* = getStyle("backgroundAttachment") != "fixed";
  66.          if(_backgroundImageBounds)
  67.          {
  68.             _loc4_ = _backgroundImageBounds.width;
  69.             _loc5_ = _backgroundImageBounds.height;
  70.          }
  71.          else
  72.          {
  73.             _loc4_ = width - _loc2_.left - _loc2_.right;
  74.             _loc5_ = height - _loc2_.top - _loc2_.bottom;
  75.          }
  76.          var _loc6_:Number = getBackgroundSize();
  77.          if(isNaN(_loc6_))
  78.          {
  79.             _loc7_ = 1;
  80.             _loc8_ = 1;
  81.          }
  82.          else
  83.          {
  84.             _loc7_ = (_loc14_ = _loc6_ * 0.01) * _loc4_ / backgroundImageWidth;
  85.             _loc8_ = _loc14_ * _loc5_ / backgroundImageHeight;
  86.          }
  87.          backgroundImage.scaleX = _loc7_;
  88.          backgroundImage.scaleY = _loc8_;
  89.          var _loc9_:Number = Math.round(0.5 * (_loc4_ - backgroundImageWidth * _loc7_));
  90.          var _loc10_:Number = Math.round(0.5 * (_loc5_ - backgroundImageHeight * _loc8_));
  91.          backgroundImage.x = _loc2_.left;
  92.          backgroundImage.y = _loc2_.top;
  93.          var _loc11_:Shape;
  94.          (_loc11_ = Shape(backgroundImage.mask)).x = _loc2_.left;
  95.          _loc11_.y = _loc2_.top;
  96.          if(_loc3_ && _loc1_ is IContainer)
  97.          {
  98.             _loc9_ -= IContainer(_loc1_).horizontalScrollPosition;
  99.             _loc10_ -= IContainer(_loc1_).verticalScrollPosition;
  100.          }
  101.          backgroundImage.alpha = getStyle("backgroundAlpha");
  102.          backgroundImage.x += _loc9_;
  103.          backgroundImage.y += _loc10_;
  104.          var _loc12_:Number = width - _loc2_.left - _loc2_.right;
  105.          var _loc13_:Number = height - _loc2_.top - _loc2_.bottom;
  106.          if(_loc11_.width != _loc12_ || _loc11_.height != _loc13_)
  107.          {
  108.             (_loc15_ = _loc11_.graphics).clear();
  109.             _loc15_.beginFill(16777215);
  110.             _loc15_.drawRect(0,0,_loc12_,_loc13_);
  111.             _loc15_.endFill();
  112.          }
  113.       }
  114.       
  115.       public function set backgroundImageBounds(param1:Rectangle) : void
  116.       {
  117.          _backgroundImageBounds = param1;
  118.          invalidateDisplayList();
  119.       }
  120.       
  121.       private function getBackgroundSize() : Number
  122.       {
  123.          var _loc3_:int = 0;
  124.          var _loc1_:Number = NaN;
  125.          var _loc2_:Object = getStyle("backgroundSize");
  126.          if(_loc2_ && _loc2_ is String)
  127.          {
  128.             _loc3_ = _loc2_.indexOf("%");
  129.             if(_loc3_ != -1)
  130.             {
  131.                _loc1_ = Number(_loc2_.substr(0,_loc3_));
  132.             }
  133.          }
  134.          return _loc1_;
  135.       }
  136.       
  137.       private function removedHandler(param1:Event) : void
  138.       {
  139.          var _loc2_:IChildList = null;
  140.          if(backgroundImage)
  141.          {
  142.             _loc2_ = parent is IRawChildrenContainer ? IRawChildrenContainer(parent).rawChildren : IChildList(parent);
  143.             _loc2_.removeChild(backgroundImage.mask);
  144.             _loc2_.removeChild(backgroundImage);
  145.             backgroundImage = null;
  146.          }
  147.       }
  148.       
  149.       private function initBackgroundImage(param1:DisplayObject) : void
  150.       {
  151.          backgroundImage = param1;
  152.          if(param1 is Loader)
  153.          {
  154.             backgroundImageWidth = Loader(param1).contentLoaderInfo.width;
  155.             backgroundImageHeight = Loader(param1).contentLoaderInfo.height;
  156.          }
  157.          else
  158.          {
  159.             backgroundImageWidth = backgroundImage.width;
  160.             backgroundImageHeight = backgroundImage.height;
  161.             if(param1 is ISimpleStyleClient)
  162.             {
  163.                ISimpleStyleClient(param1).styleName = styleName;
  164.             }
  165.          }
  166.          var _loc2_:IChildList = parent is IRawChildrenContainer ? IRawChildrenContainer(parent).rawChildren : IChildList(parent);
  167.          var _loc3_:Shape = new FlexShape();
  168.          _loc3_.name = "backgroundMask";
  169.          _loc3_.x = 0;
  170.          _loc3_.y = 0;
  171.          _loc2_.addChild(_loc3_);
  172.          var _loc4_:int = _loc2_.getChildIndex(this);
  173.          _loc2_.addChildAt(backgroundImage,_loc4_ + 1);
  174.          backgroundImage.mask = _loc3_;
  175.       }
  176.       
  177.       public function get backgroundImageBounds() : Rectangle
  178.       {
  179.          return _backgroundImageBounds;
  180.       }
  181.       
  182.       public function get hasBackgroundImage() : Boolean
  183.       {
  184.          return backgroundImage != null;
  185.       }
  186.       
  187.       private function completeEventHandler(param1:Event) : void
  188.       {
  189.          if(!parent)
  190.          {
  191.             return;
  192.          }
  193.          var _loc2_:DisplayObject = DisplayObject(LoaderInfo(param1.target).loader);
  194.          initBackgroundImage(_loc2_);
  195.          layoutBackgroundImage();
  196.          dispatchEvent(param1.clone());
  197.       }
  198.       
  199.       override protected function updateDisplayList(param1:Number, param2:Number) : void
  200.       {
  201.          var cls:Class = null;
  202.          var newStyleObj:DisplayObject = null;
  203.          var loader:Loader = null;
  204.          var loaderContext:LoaderContext = null;
  205.          var message:String = null;
  206.          var unscaledWidth:Number = param1;
  207.          var unscaledHeight:Number = param2;
  208.          if(!parent)
  209.          {
  210.             return;
  211.          }
  212.          var newStyle:Object = getStyle("backgroundImage");
  213.          if(newStyle != backgroundImageStyle)
  214.          {
  215.             removedHandler(null);
  216.             backgroundImageStyle = newStyle;
  217.             if(newStyle && newStyle as Class)
  218.             {
  219.                cls = Class(newStyle);
  220.                initBackgroundImage(new cls());
  221.             }
  222.             else if(newStyle && newStyle is String)
  223.             {
  224.                try
  225.                {
  226.                   cls = Class(getDefinitionByName(String(newStyle)));
  227.                }
  228.                catch(e:Error)
  229.                {
  230.                }
  231.                if(cls)
  232.                {
  233.                   newStyleObj = new cls();
  234.                   initBackgroundImage(newStyleObj);
  235.                }
  236.                else
  237.                {
  238.                   loader = new FlexLoader();
  239.                   loader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeEventHandler);
  240.                   loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,errorEventHandler);
  241.                   loader.contentLoaderInfo.addEventListener(ErrorEvent.ERROR,errorEventHandler);
  242.                   loaderContext = new LoaderContext();
  243.                   loaderContext.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain);
  244.                   loader.load(new URLRequest(String(newStyle)),loaderContext);
  245.                }
  246.             }
  247.             else if(newStyle)
  248.             {
  249.                message = resourceManager.getString("skins","notLoaded",[newStyle]);
  250.                throw new Error(message);
  251.             }
  252.          }
  253.          if(backgroundImage)
  254.          {
  255.             layoutBackgroundImage();
  256.          }
  257.       }
  258.       
  259.       private function errorEventHandler(param1:Event) : void
  260.       {
  261.       }
  262.    }
  263. }
  264.